package com.fyzk.activity.lottery.jc.football.newJz.data;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.TextView;


import com.tyjc.lottery.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by fanxs11 on 16/5/4.
 *
 * 欧赔view
 */
public class OuPeiView extends LinearLayout implements CompoundButton.OnCheckedChangeListener{
    private Context context;
    private int dateType = 0;   // 数据类型（0：欧指，1：亚盘）
    private String str1 = "";
    private String str2 = "";
    private TextView tishi_tv;
    private ListView listView;
    private OuPeiAdapter adapter;
    private List<JCZQ_EuropeDataRespose> infos = new ArrayList<>();

    private RadioButton peilv_rb;   // 赔率数据
    private RadioButton kaili_rb;   // 凯利指数
    private TextView textView1;     // 初始赔率（选择“赔率数据”），最新概率（选择“凯利指数”）
    private TextView textView2;     // 即时赔率（选择“赔率数据”），最新凯利指数（选择“凯利指数”）
    private LinearLayout spf_ll;    // 凯利指数对应的 胜平负的值
    private TextView fanhuailv_tv;  // 凯利指数对应的返还率
    private TextView ping_tv;  // 凯利指数对应的返还率
    private TextView ping_tv2;  // 凯利指数对应的返还率

    public OuPeiView(Context context, AttributeSet attrs, int defStyle, int dateType) {
        super(context, attrs, defStyle);
        this.context = context;
        this.dateType = dateType;

        if (dateType == 0) {
            str1 = "初始赔率";
            str2 = "即时赔率";
        } else {
            str1 = "初始盘口";
            str2 = "即时盘口";
        }
        initView();
    }

    public OuPeiView(Context context, AttributeSet attrs, int dateType) {
        this(context, attrs, 0, dateType);
    }

    public OuPeiView(Context context, int dateType) {
        this(context, null, dateType);
    }

    public void initView(){
        View.inflate(context, R.layout.jc_ouyaxi_view, this);


        peilv_rb = (RadioButton) findViewById(R.id.jc_ouyaxi_rb_peilv);
        kaili_rb = (RadioButton) findViewById(R.id.jc_ouyaxi_rb_kaili);
        peilv_rb.setOnCheckedChangeListener(this);
        kaili_rb.setOnCheckedChangeListener(this);

        textView1 = (TextView) findViewById(R.id.jc_ouyaxi_tv1);
        textView2 = (TextView) findViewById(R.id.jc_ouyaxi_tv2);
        spf_ll = (LinearLayout) findViewById(R.id.jc_ouyaxi_spf_ll);
        fanhuailv_tv = (TextView) findViewById(R.id.jc_ouyaxi_fanhuan_tv);
        ping_tv = (TextView) findViewById(R.id.jc_ouyaxi_ping_tv);
        ping_tv2 = (TextView) findViewById(R.id.jc_ouyaxi_ping_tv2);

        tishi_tv = (TextView) findViewById(R.id.jc_ouyaxi_tishi);

        listView = (ListView) findViewById(R.id.jc_ouyaxi_listview);
        if (dateType == 0) {
            adapter = new EuropeAdapter(context, infos);
            ping_tv.setVisibility(View.VISIBLE);
            ping_tv2.setVisibility(View.VISIBLE);
        } else {
            adapter = new AsiaAdapter(context, infos);
            ping_tv.setVisibility(View.GONE);
            ping_tv2.setVisibility(View.GONE);
        }
        listView.setAdapter(adapter);

        textView1.setText(str1);
        textView2.setText(str2);
    }

    @Override
    public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
        if (b) {
            switch (compoundButton.getId()) {
                case R.id.jc_ouyaxi_rb_peilv:   // 赔率数据
                    textView1.setText(str1);
                    textView2.setText(str2);
                    spf_ll.setVisibility(View.GONE);
                    fanhuailv_tv.setVisibility(View.GONE);
                    this.adapter.setType(0);
                    break;
                case R.id.jc_ouyaxi_rb_kaili:   // 凯利指数
                    textView1.setText("最新概率");
                    textView2.setText("最新凯利指数");
                    spf_ll.setVisibility(View.VISIBLE);
                    fanhuailv_tv.setVisibility(View.VISIBLE);
                    this.adapter.setType(1);
                    break;
            }
        }
    }

    public void setInfos(List<JCZQ_EuropeDataRespose> infos){
        this.infos = infos;

        if (this.infos == null || this.infos.size() == 0) {
            tishi_tv.setVisibility(View.VISIBLE);
            listView.setVisibility(View.GONE);
        } else {
            tishi_tv.setVisibility(View.GONE);
            listView.setVisibility(View.VISIBLE);
            this.adapter.setInfos(this.infos);
        }

    }
}
